package main

import "fmt"

func main() {
	// arithmeticsOperators()
	// relationalOperators()
	//logicalOperators()
	//assignmentOperators()
	exchangeAB(3, 8)
}

func arithmeticsOperators() {
	// 除法、取模、自增、自减重点学习
	// 除法
	// 如果运算的数都是整数，结果也保留整数，直接舍弃小数
	fmt.Println("10 / 3 =", 10/3)
	fmt.Println("5 / 2 =", 5/3)
	// 即使类型为浮点数，也是取整
	var a float32 = 5 / 2
	fmt.Printf("type of a = %T\n", a)
	fmt.Println("a =", a)

	// 如果希望保留小数，则需要浮点数参与运算
	fmt.Println("10.0 / 3 =", 10.0/3)

	fmt.Println("--------------------------------")

	// 取模，结果是除法的余数
	fmt.Println("10 % 3 =", 10%3)
	fmt.Println("10 % -3 =", 10%-3)
	fmt.Println("10 % 10 =", 10%10)
	fmt.Println("10 % -10 =", 10%-10)

	fmt.Println("--------------------------------")

	// 自增自减
	var b int = 10
	fmt.Println("b =", b)
	fmt.Println("b++")
	b++
	fmt.Println("b =", b)

	fmt.Println("--------------------------------")

	var c int = 5
	fmt.Println("c =", c)
	fmt.Println("c--")
	c--
	fmt.Println("c =", c)

}

func relationalOperators() {
	var num1 int = 1
	var num2 int = 2
	fmt.Println("num1 =", num1, "num2 =", num2)
	fmt.Println("num1 == num2 is", num1 == num2)
	fmt.Println("num1 != num2 is", num1 != num2)
	fmt.Println("num1 < num2 is", num1 < num2)
	fmt.Println("num1 > num2 is", num1 > num2)
	fmt.Println("num1 <= num2 is", num1 <= num2)
	fmt.Println("num1 >= num2 is", num1 >= num2)
}

func logicalOperators() {
	var num1 int = 1
	var num2 int = 2
	if num1 > 1 && num1 < num2 {
		fmt.Println("result 1")
	} else {
		fmt.Println("result 2")
	}
	fmt.Println("--------------------------------")
	if num1 > 1 || num1 < num2 {
		fmt.Println("result 3")
	} else {
		fmt.Println("result 4")
	}
	fmt.Println("--------------------------------")
	if !(num1 > 1) {
		fmt.Println("result 5")
	} else {
		fmt.Println("result 6")
	}

	fmt.Println("--------------------------------")

	if !(getConditionalFalse() && getConditionalTrue()) {
		fmt.Println("just print get false")
	}

	fmt.Println("--------------------------------")

	if getConditionalTrue() || getConditionalFalse() {
		fmt.Println("just print get false")
	}
}

func getConditionalTrue() bool {
	fmt.Println("get true")
	return true
}

func getConditionalFalse() bool {
	fmt.Println("get false")
	return false
}

func assignmentOperators() {
	var num1 int = 1
	var num2 int = 1
	var num3 int = 1
	var num4 int = 2
	var num5 int = 22
	var num6 int = 11
	var num7 int = 8
	var num8 int = 8
	var num9 int = 8
	var num10 int = 9
	var num11 int = 8
	fmt.Println("--------------------------------")
	fmt.Println("num1 = ", num1)
	num1 = 1 + 2
	fmt.Println("num1 = 1 + 2 ==> num1 = ", num1)
	fmt.Println("--------------------------------")
	fmt.Println("num2 = ", num2)
	num2 += 10
	fmt.Println("num2 += 10 ==> num2 = ", num2)
	fmt.Println("--------------------------------")
	fmt.Println("num3 = ", num3)
	num3 -= 10
	fmt.Println("num3 -= 10 ==> num3 = ", num3)
	fmt.Println("--------------------------------")
	fmt.Println("num4 = ", num4)
	num4 *= 10
	fmt.Println("num4 *= 10 ==> num4 = ", num4)
	fmt.Println("--------------------------------")
	fmt.Println("num5 = ", num5)
	num5 /= 10
	fmt.Println("num5 /= 10 ==> num5 = ", num5)
	fmt.Println("--------------------------------")
	fmt.Println("num6 = ", num6)
	num6 %= 10
	fmt.Println("num6 %= 10 ==> num6 = ", num6)
	fmt.Println("--------------------------------")
	fmt.Println("num7 = ", num7)
	num7 <<= 2
	fmt.Println("num7 <<= 2 ==> num7 = ", num7)
	fmt.Println("--------------------------------")
	fmt.Println("num8 = ", num8)
	num8 >>= 2
	fmt.Println("num8 >>= 2 ==> num8 = ", num8)
	fmt.Println("--------------------------------")
	fmt.Println("num9 = ", num9)
	num9 &= 9
	fmt.Println("num9 &= 9 ==> num9 = ", num9)
	fmt.Println("--------------------------------")
	fmt.Println("num10 = ", num10)
	num10 ^= 3
	fmt.Println("num10 ^= 3 ==> num10 = ", num10)
	fmt.Println("--------------------------------")
	fmt.Println("num3 = ", num11)
	num11 |= 1
	fmt.Println("num11 |= 1 ==> num11 = ", num11)
	fmt.Println("--------------------------------")
}

func exchangeAB(num1 int, num2 int) {
	fmt.Printf("num1 = %d, num2 = %d \n", num1, num2)
	num1 += num2
	num2 = num1 - num2
	num1 -= num2
	fmt.Printf("num1 = %d, num2 = %d \n", num1, num2)
}
